//
//  Floor.cpp
//  宿舍管理系统
//
//  Created by 孟强定 on 2020/6/26.
//  Copyright © 2020 mqd. All rights reserved.
//

#include "Floor.hpp"

Floor::Floor(int n):num(n){
    rooms = new Room[num];
}
void Floor::init(int buildingId, int floorId){
    this->buildingId=buildingId;
    this->floorId=floorId;
    for(int i=0;i<num;i++){
        rooms[i].init(buildingId,floorId,i+1);
    }

}
void Floor::autoDistribute(){
    for(int i=0;i<num;i++){
        rooms[i].autoDistribute();
    }
}
bool Floor::autoDistributeOne(Student * stu){
    if (!stu) return 0;
    for(int i=0;i<num;i++){
        if (rooms[i].autoDistributeOne(stu)) return 1;
    }
    return 0;
}
bool Floor::manualDistributeOne(Student* stu, int roomId){
    if (!stu) return 0;
    if (roomId<0 || roomId>num) return 0;
    return rooms[roomId].autoDistributeOne(stu);
}


bool Floor::find(int room){
    if (room<0 || room>=num) return 0;
    rooms[room].print();
    return 1;
}

bool Floor::delOne(Student *stu){
    if (!stu) return 0;
    return rooms[stu->getRoomId()-1].delOne(stu);
}
